<template>
  <div class="home">
    <div class="lists">
      <template v-for="item in lists">
        <drag
        :key="item.id"
        :transfer-data="{ id: item.id }"
         class="item" v-if="item.drag"></drag>
        <drop 
				@drop="handleDrop(item.id, ...arguments)"
        :key="item.id"
        class="item drop" v-else></drop>
      </template>
    </div>
  </div>
</template>

<script>

export default {
  name: 'Home',
  data(){
    return {
      lists:[{
        name: '1',
        drag: true,
        id: 1
      },{
        name: '2',
        drag: true,
        id: 2
      },{
        name: '3',
        drag: false,
        id: 3
      },{
        name: '4',
        drag: true,
        id: 4
      },{
        name: '5',
        drag: false,
        id: 5
      },{
        name: '6',
        drag: false,
        id: 6
      }],
			dragging: null,
    }
  },
  methods: {
			handleDrop(id,obj) {
        let dragIndex = this.lists.findIndex(item => item.id === obj.id)
        let dropIndex = this.lists.findIndex(item => item.id === id)
        this.lists[dragIndex]=[this.lists[dropIndex], this.lists[dropIndex]=this.lists[dragIndex]][0]
        this.$forceUpdate()
        console.log(dragIndex,dropIndex);
			},
     
  },
}
</script>
<style lang="scss">
  .lists {
    width: 400px;
    display: flex;
    flex-wrap: wrap;
    .item {
      width: 100px;
      height: 100px;
      background-color: #666;
      margin-right: 10px;
      margin-bottom: 10px;
      text-align: center;
      line-height: 100px;
      font-size: 80px;
      &.drop {
        background-color: #eee;
      }
    }
  }
</style>
